﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Radiation.Common
{
    public class LoggerContainer
    {
        private List<string> m_data = new List<string>();

        public event EventHandler<GenericEventArgs> ItemAdded;

        public int Count
        {
            get { return m_data.Count; }
        }

        public int Capacity
        {
            get { return m_data.Capacity; }
        }

        public string this[int id]
        {
            get
            {
                if (id >= 0 && id < m_data.Count)
                    return m_data[id];
                return null;
            }
        }

        public LoggerContainer()
        {
            m_data = new List<string>();
        }

        public void add(string text)
        {
            lock (m_data)
            {
                m_data.Add(text);
            }

            OnItemAdded(text);
        }

        public void clear()
        {
            lock (m_data)
            {
                m_data.Clear();
            }
        }

        protected virtual void OnItemAdded(string item)
        {
            GenericEventArgs newGenericEventArgs = new GenericEventArgs();
            newGenericEventArgs["message"] = item;

            if (ItemAdded != null)
                ItemAdded(this, newGenericEventArgs);
        }
    }
}
